﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SBLib.Common
{
    class ConvertFunc
    {
        /// <summary>
        /// Convert string to stream
        /// </summary>
        /// <param name="ParamText">Any string</param>
        /// <returns></returns>
        public static MemoryStream ConvertStringToStream(string ParamText)
        {
            try
            {
                //To convert a C# String to a MemoryStream object, use the GetBytes Encoding method to create a byte array, 
                //then pass that to the MemoryStream constructor:
                byte[] byteArray = Encoding.ASCII.GetBytes(ParamText);
                MemoryStream stream = new MemoryStream(byteArray);
                return stream;

            }
            catch (Exception)
            {

                return null;
            }
        }

        /// <summary>
        /// Convert stream to string
        /// </summary>
        /// <param name="ParamStream">Stream</param>
        /// <returns></returns>
        public static string ConvertStreamToString(MemoryStream ParamStream)
        {
            try
            {
                StreamReader reader = new StreamReader(ParamStream);
                string text = reader.ReadToEnd();
                return text;
            }
            catch (Exception ex)
            {

                return ex.Message;
            }
        
        }

        /// <summary>
        /// Convert Byte array to string
        /// </summary>
        /// <param name="ParamByte">Byte array</param>
        /// <returns></returns>
        public static string ConvertByteArrayToString(byte[] ParamByte)
        {
            try
            {
                return Encoding.ASCII.GetString(ParamByte);
            }
            catch (Exception ex)
            {

                return ex.Message;
            }
        }

        /// <summary>
        /// Convert String to byte array
        /// </summary>
        /// <param name="ParamString">Any string</param>
        /// <returns></returns>
        public static byte[] ConvertStringToByteArray(string ParamString)
        {
            try
            {
                return Encoding.ASCII.GetBytes(ParamString);
            }
            catch (Exception)
            {

                return null;
            }
        }


        public static DateTime? ConvertOneTimezoneToAnother()
        {
            try
            {
                //Converts a time from one time zone to another based on time zone identifiers.
                return null;
            }
            catch (Exception)
            {

                return null;
            }
        
        }
    }
}
